<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>众筹主题管理</title>
    <%@include file="../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form class="layui-form" action="${ctx}/crowdfund/event/list.do" id="myForm" method="post">
                <input type="hidden" name="pageNo" id="pageNo"/>
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline"><label class="search-form-lable">主题名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" autocomplete="off" class="layui-input"
                                           value="${event.name}" placeholder="请输入主题名称">
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable">发布者</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="memberName" autocomplete="off" class="layui-input"
                                           value="${input.memberName}" placeholder="请输入发布者">
                                </div>
                            </li>
                            <li class="form-item-inline"><label class="search-form-lable">主题状态</label>
                                <div class="layui-input-inline">
                                    <select name="progress">
                                        <option value="">全部</option>
                                        <option value="1" ${event.progress == 1 ? 'selected' : ''}>进行中</option>
                                        <option value="2" ${event.progress == 2 ? 'selected' : ''}>已截止</option>
                                    </select>
                                </div>
                            </li>

                            <li class="form-item-inline"><label class="search-form-lable">审核状态</label>
                                <div class="layui-input-inline">
                                    <select name="checkStatus">
                                        <option value="">全部</option>
                                        <option value="0" ${event.checkStatus == 0 ? 'selected' : ''}>待审核</option>
                                        <option value="1" ${event.checkStatus == 1 ? 'selected' : ''}>审核通过</option>
                                        <option value="2" ${event.checkStatus == 2 ? 'selected' : ''}>已拒绝</option>
                                    </select>
                                </div>
                            </li>

                            <li class="form-item-inline"><label class="search-form-lable">合作商类型</label>
                                <div class="layui-input-inline">
                                    <select name="partnerType">
                                        <option value="">全部</option>
                                        <option value="0" ${event.partnerType == 0 ? 'selected="selected"' : ''}>系统客户
                                        </option>
                                        <option value="1" ${event.partnerType == 1 ? 'selected="selected"' : ''}>大客户
                                        </option>
                                        <option value="2" ${event.partnerType == 2 ? 'selected="selected"' : ''}>地接客户
                                        </option>
                                        <option value="3" ${event.partnerType == 3 ? 'selected="selected"' : ''}>运营客户
                                        </option>
                                        <option value="4" ${event.partnerType == 4 ? 'selected="selected"' : ''}>注册客户
                                        </option>
                                    </select>
                                </div>
                            </li>
                        </ul>
                        <ul class="search-form-content">
                            <li class="form-item"><label class="search-form-lable">发布时间</label>
                                <div class="check-btn-inner" id="timeType">
                                    <a id="all" href="javascript:void(0);"
                                       onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                    <a href="javascript:void(0);"
                                       onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                    <input type="hidden" name="timeType" value="${input.timeType}"/>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createStart"
                                               value="${input.createStart}" placeholder="开始日">
                                    </div>
                                    -
                                    <div class="layui-input-inline">
                                        <input class="layui-input" type="text" name="createEnd"
                                               value="${input.createEnd}" placeholder="截止日">
                                    </div>
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns">
                                    <a class="layui-btn layui-btn-danger"
                                       href="javascript:submitFunction('#myForm')">查询</a>
                                    <a class="layui-btn layui-btn-normal"
                                       href="javascript:resetFunction('#myForm')">重置</a>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <div class="list-content">
                <ul class="num mt10">
                    <div class="l">
                        <li class="f16">共<span class="red">${page.totalCount}</span>条数据</li>
                    </div>
                    <p class="cl"></p>
                </ul>
                <div class="cl">
                    <table class="layui-table">
                        <colgroup>
                            <col width="65px">
                            <col width="18%">
                            <col width="10%">
                            <col width="105px">
                            <col width="150px">
                            <col width="150px">
                            <col width="75px">
                            <col width="75px">
                            <col width="100px">
                            <col width="95px">
                            <col>
                            <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>主题名称</th>
                            <th>发布者</th>
                            <th>合作商类型</th>
                            <th>发布时间</th>
                            <th>截止时间</th>
                            <th>状态</th>
                            <th>项目数</th>
                            <th>审核状态</th>
                            <th>添加</th>
                            <th>分析</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="event" items="${list}" varStatus="st">
                            <c:set var="nowDate" value="<%=new Date()%>"></c:set>
                            <tr>
                                <td>${page.limit * (page.page-1) + st.count}</td>
                                <td class="ellipsis-1 tl" title=" ${event.name}">
                                    <a href="${ctx}/crowdfund/event/eventDetail.do?eventId=${event.id}">${event.name}</a>
                                </td>
                                <td class="table-member"
                                    onclick="openDialogShow('用户名片','${ctx}/system/member/memberView.do?id=${event.createBy}','400px','470px')">
                                    <div class="member-cell">
                                        <div class="member-logo common-img">
                                            <img src="<c:if test="${event.logo != null}">${event.logo}?imageMogr2/auto-orient/crop/126x126</c:if>"
                                                 alt="" onerror="txz.errImg(this)" onload="txz.imgLoad(this)">
                                        </div>
                                        <div class="member-name ellipsis-1">
                                            <a class="blue" title="${event.realname}"
                                               href="javascript:void(0);">${event.realname}</a>
                                        </div>
                                    </div>
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${empty event.partnerType || event.partnerType == 0}">
                                            系统客户
                                        </c:when>
                                        <c:when test="${not empty event.partnerType && event.partnerType == 1}">
                                            <span class="green">大客户</span>
                                        </c:when>
                                        <c:when test="${not empty event.partnerType && event.partnerType == 2}">
                                            <span style="color: #3b97d7;">地接客户</span>
                                        </c:when>
                                        <c:when test="${not empty event.partnerType && event.partnerType == 3}">
                                            <span style="color: #6f5499;">运营客户</span>
                                        </c:when>
                                        <c:when test="${not empty event.partnerType && event.partnerType == 4}">
                                            <span style="color: #6f5499;">注册客户</span>
                                        </c:when>
                                    </c:choose>
                                </td>
                                <td><fmt:formatDate value="${event.createDate}" pattern="yyyy-MM-dd HH:mm"/></td>
                                <td><fmt:formatDate value="${event.endTime}" pattern="yyyy-MM-dd HH:mm"/></td>
                                <td>
                                    <c:if test="${event.endTime > nowDate}">
                                        <span class="red">进行中</span>
                                    </c:if>
                                    <c:if test="${event.endTime < nowDate}">
                                        <span>已截止</span>
                                    </c:if>
                                </td>
                                <td>
                                    <a href="${ctx}/activity/activity/zcActivityList.do?eventId=${event.id}"
                                       target="_self">${event.crowdfundNum}</a>
                                </td>
                                <td title="${event.checkRemark}" >
                                    <c:choose>
                                        <c:when test="${event.checkStatus==0}">待审核</c:when>
                                        <c:when test="${event.checkStatus==1}">
                                            <span style="color: green;">审核通过</span>
                                        </c:when>
                                        <c:when test="${event.checkStatus==2}">
                                           <span><a href="javascript:showAuthor1('${event.checkRemark}')"
                                                    class="red">已拒绝&nbsp;&nbsp;<font
                                                   style="color: #5e5e5e">▼</font></a> </span>
                                        </c:when>
                                    </c:choose>
                                </td>
                                <td>
                                    <c:if test="${event.endTime > nowDate}">
                                        <a href="javaScript:;"
                                           onclick="javascript:publishCrowdfund('${event.checkStatus}','${ctx}/crowdfund/event/copyEvent.do?eventId=${event.id}');">
                                            发布项目</a>
                                    </c:if>
                                </td>
                                <td class="tb-opts">
                                    <div class="comm-opts">
                                        <a href="${ctx}/crowdfund/project/listForEvent.do?eventId=${event.id}"
                                           target="_self">数据查看</a>
                                        <a target="_blank" href="${ctx}/crowdfund/analyze/list.do?eventId=${event.id}"
                                           target="_self">数据分析</a>
                                        <a target="_blank"
                                           href="${ctx}/crowdfund/detailCount/eventDataTable.do?eventId=${event.id}"
                                           target="_blank">统计报表</a>
                                    </div>
                                </td>
                                <td class="tb-opts">
                                    <div class="comm-opts">
                                        <a class="qr-btn"
                                           href="javascript:txz.openQrDialog({
                                                               title:'扫码二维码可预览分享',
                                                               detailList:[
                                                                   {
                                                                   title:'报名信息验证',
                                                                   url:'${event.bindQrCode}'
                                                                   }
                                                               ]
                                                               })">报名验证二维码</a>
                                        <a href="javascript:showCopartnerDialog('${event.name}','${event.id}')">查看合伙人</a>
                                        <a href="${ctx}/notify/template/listForEvent.do?targetId=${event.id}">短信推送</a>
                                        <a href="${ctx}/crowdfund/event/copyView.do?id=${event.id}"> 复制众筹主题</a>
                                        <a href="javascript:createCircle('${event.id}')" class="over-tip"
                                           title="点击生成圈子，即可在【圈子管理】查看创建的圈子，圈子集成通讯录和信息动态，可以将二维码分享给想邀请的用户，用户可以申请加入圈子。">生成圈子</a>
                                        <a href="javascript:createGatherInfo('${event.id}')" class="over-tip"
                                           title="点击生成信息收集项目，即可在【人员信息收集分组】查看人员信息，主要可以收集参与活动人员的基本信息、保险信息、行程信息等。">生成信息收集项目</a>
                                        <a href="${ctx}/crowdfund/event/view.do?id=${event.id}" target="_self">编辑</a>
                                        <a href="javascript:txz.deleteObject('确定删除主题吗', '${ctx}/crowdfund/event/delete.do?id=${event.id}');"
                                           target="_self">删除</a>
                                    </div>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
            <div id="page_content" class="page-container"></div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
    <div id="copartnerList" style="padding: 0px 10px"></div>

    <div id="authorDialog1">
        <table class="layui-table" lay-skin="line">
            <tbody>
            <tr>
                <td>
                    <div class="member-name">

                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <script type="text/html" id="copartner_template">
        <table class="layui-table">
            <colgroup>
                <col>
                <col>
                <col>
            </colgroup>
            <thead>
            <tr>
                <th>昵称</th>
                <th>手机</th>
                <th>参与时间</th>
            </tr>
            </thead>
            <tbody>
            {{# layui.each(d.data, function(index, item){ }}
            <tr>
                <td class="table-member">
                    <div class="member-cell">
                        <div class="member-logo common-img">
                            <img src="{{ item.logo ? item.logo + '?imageMogr2/auto-orient/crop/126x126':'' }}" alt=""
                                 onerror="txz.errImg(this)" onload="txz.imgLoad(this)">
                        </div>
                        <div class="member-name ellipsis-1"><a class="blue" title="{{ item.realname }}"
                                                               href="javascript:void(0);">{{ item.realname }}</a></div>
                    </div>
                </td>
                <td>{{ item.mobile }}</td>
                <td>
                    {{# if(util.isValid(item.joinTime)){ }}
                    {{ util.getDateStr(item.joinTime).Format('yyyy-MM-dd hh:mm') }}
                    {{# } }}
                </td>
            </tr>
            {{# }); }}
            {{# if(d.data.length == 0){ }}
            <tr>
                <td colspan="3">暂无合伙人</td>
            </tr>
            {{# } }}
            </tbody>
        </table>
    </script>
</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '众筹主题管理',
            curr: true
        }],
        info: '<span class="f12">共<b>${page.totalCount}</b>条记录',
        btns: [{
            name: '添加主题',
            icon: 'add',
            href: '${ctx}/crowdfund/event/view.do'
        }]
    });
    var laytpl = null;
    $(function () {
        var index = null;
        $(".over-tip").mouseover(function () {
            index = txz.openQTip(this);
        }).mouseout(function () {
            layer.close(index);
        });
        layui.use(['laytpl'], function () {
            laytpl = layui.laytpl;
        });

        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });

        //加载日历
        layui.use(['laytpl', 'laypage', 'element', 'laydate'], function () {
            var laytpl = layui.laytpl, laydate = layui.laydate, laypage = layui.laypage, element = layui.element;
            element.on('tab(type)', function (data) {
                if (data.index == 0) {
                    $('#status').val(0);
                    $('#myForm').submit();
                }
                else if (data.index == 1) {
                    $('#status').val(1);
                    $('#myForm').submit();
                }
            });

            // 查询开始日期
            var start = {
                elem: 'input[name=s_start]'
            };

            var end = {
                elem: 'input[name=s_end]'
            };
            laydate.render(start);
            laydate.render(end);

            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);
        });

    });

    function openHelpDialog() {
        txz.openHelpDialog({
            title: '手机效果预览',
            describe: '众筹主题指的是，可以对这个主题所关联的所有众筹项目进行管理，关联所有的众筹项目数据。',
            detailList: [{
                text: '1/众筹项目详情',
                url: '${ctx}/image/dialog/zc_1.jpg'
            }, {
                text: '2/活动详情',
                url: '${ctx}/image/dialog/zc_2.jpg'
            }, {
                text: '3/活动信息',
                url: '${ctx}/image/dialog/zc_3.jpg'
            }]
        })
    }

    function createCircle(actId) {
        var content = "确定要生成吗？请选择生成<br/><label for='all1' class='mr10'><input type='radio' id='all1' name='type' value='2' checked='checked' >全部报名人员</label>" +
            "<label for='success'><input type='radio' id='success' name='type' value='1' >已成功报名人员</label>";
// 		content = "确定要生成吗？";
        layer.confirm(content, {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            var type = $("[name=type]:checked").val() || '2';
            layer.close(index);
            //loading层
            var loadIndex = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            $.post("${ctx}/crowdfund/event/createCircle.do", {
                eventId: actId,
                type: type
            }, function (data) {
                layer.close(loadIndex);
                setTimeout(function () {
                    if (data.success == true) {
                        util.layerMsgSuccess("生成成功")
                    } else {
                        util.layerMsgError("生成失败")
                    }
                });
            })
        });
    }

    function createGatherInfo(actId) {
        var content = "确定要生成吗？请选择生成<br/><label for='all1' class='mr10'><input type='radio' id='all1' name='type' value='2' checked='checked' >全部报名人员</label>" +
            "<label for='success'><input type='radio' id='success' name='type' value='1' >已成功报名人员</label>";
// 		content = "确定要生成吗？";
        layer.confirm(content, {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            var type = $("[name=type]:checked").val() || '2';
            layer.close(index);
            //loading层
            var loadIndex = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            $.post("${ctx}/crowdfund/event/createGatherInfo.do", {
                eventId: actId,
                type: type
            }, function (data) {
                layer.close(loadIndex);
                setTimeout(function () {
                    if (data.success == true) {
                        util.layerMsgSuccess("生成成功")
                    } else {
                        util.layerMsgError("生成失败")
                    }
                });
            })
        });
    }

    /**
     * 查看合伙人
     * @param targetName 主题名称
     * @param eventId 主题id
     */
    function showCopartnerDialog(targetName, eventId) {
        var setPayIndex = layer.open({
            type: 1,
            area: ['600px', '500px'],
            title: '查看“' + targetName + '”主题的已分配合伙人',
            content: $("#copartnerList"),
            btn: ['关闭'],
            success: function () { // 弹出后回调
                $.post("${ctx}/crowdfund/event/getCopartnerByEvent.do", {eventId: eventId}, function (res) {
                    if (res.success) {
                        var content = $("#copartnerList");
                        $(content).html("");
                        var getTpl = $("#copartner_template").html();
                        laytpl(getTpl).render(res, function (html) {
                            content.append(html);
                        });
                    }
                })
            },
            end: function () { // 销毁后回调
                $("#copartnerList").html("");
            },
            yes: function () { // 确定按钮
                layer.close(setPayIndex);
            }
        });
    }

    /**
     * 发布众筹项目
     * @param checkStatus
     * @param url
     */
    function publishCrowdfund(checkStatus, url) {
        if (checkStatus != 1) {
            layer.msg('审核通过后方可发布众筹项目<br/>&nbsp;&nbsp;&nbsp;&nbsp;请耐心等待平台审核', {
                icon: 0,
                title: '系统提示',
                time: 2500
            });
        } else {
            window.location.href = url;
        }
    }


    function showAuthor1(remarks) {
        var setPayIndex = layer.open({
            type: 1,
            area: '400px',
            title: '查看备注',
            content: $("#authorDialog1"),
            btn: ['关闭'],
            success: function () { // 弹出后回调
                if (remarks != null && remarks.length > 0) {
                    $("#authorDialog1").find(".member-name").text(remarks);
                } else {
                    util.layerMsgError("暂无备注");
                }
            },
            end: function () { // 销毁后回调
                $("#authorDialog1").find(".member-name").text('');
            },
            yes: function () { // 确定按钮
                layer.close(setPayIndex);
            }
        });
    }
</script>
</body>
</html>